﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfUsercontrol.UserControls.TaControl
{
    /// <summary>
    /// TopNavigationMenu.xaml 的交互逻辑
    /// </summary>
    public partial class TopNavigationMenu : UserControl
    {
        public TopNavigationMenu()
        {
            InitializeComponent();
        }


        public int SelectButton
        {
            get { return (int)GetValue(SelectIndexProperty); }
            set { SetValue(SelectIndexProperty, value); }
        }

        // Using a DependencyProperty as the backing store for SelectIndex.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty SelectIndexProperty =
            DependencyProperty.Register("SelectIndex", typeof(int), typeof(TopNavigationMenu), new PropertyMetadata(0, OnSelectedIndexChanged));
        private static void OnSelectedIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {

            if (d is TopNavigationMenu control)
            {
                control.UpdateUnderline();
            }
        }
        private void UpdateUnderline()
        {
            // 先隐藏所有下划线
            HideAllUnderlines();

            // 显示对应下划线
            switch (SelectButton)
            {
                case 1:
                    Underline1.Visibility = Visibility.Visible;
                    break;
                case 2:
                    Underline2.Visibility = Visibility.Visible;
                    break;
                case 3:
                    Underline3.Visibility = Visibility.Visible;
                    break;
                case 4:
                    Underline4.Visibility = Visibility.Visible;
                    break;
                case 5:
                    Underline5.Visibility = Visibility.Visible;
                    break;
            }
        }

        private void HideAllUnderlines()
        {
            Underline1.Visibility = Visibility.Collapsed;
            Underline2.Visibility = Visibility.Collapsed;
            Underline3.Visibility = Visibility.Collapsed;
            Underline4.Visibility = Visibility.Collapsed;
            Underline5.Visibility = Visibility.Collapsed;
        }



        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            await ToPagesAsync(1);
        }



        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            await ToPagesAsync(2);
        }

        private async void Button_Click_2(object sender, RoutedEventArgs e)
        {
            await ToPagesAsync(3);
        }

        private async void Button_Click_3(object sender, RoutedEventArgs e)
        {
            await ToPagesAsync(4);
        }

        private async void Button_Click_4(object sender, RoutedEventArgs e)
        {
            await ToPagesAsync(5);
        }

        private async Task ToPagesAsync(int pageId)
        {
            // 隐藏所有下划线
            //HideAllUnderlines(sender);



            var window = Window.GetWindow(this); // 获取当前 UserControl 所在的 Window
            if (window != null)
            {
                switch (pageId)
                {
                    case 1:

                        //OutboundingPage1ViewModel.ShowWindow();
                        break;
                    case 2:

                        //OutboundingPage2ViewModel.ShowWindow();
                        break;
                    case 3:

                        //OutboundingPage3ViewModel.ShowWindow();
                        break;

                    case 4:
                        //OutboundingPage4ViewModel.ShowWindow();
                        break;
                    case 5:
                        //OutboundingPage5ViewModel.ShowWindow();
                        break;
                    default:
                        break;
                }
                await Task.Delay(500);
                window.Close();
            }
        }
    }
}
